import { Inject, Injectable } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { InjectRepository } from '@nestjs/typeorm';
import { EntityRepository, In, MongoRepository, Repository } from 'typeorm';
import { AccountVo } from '../../controllers/account/vo/account.vo';
import { AccountEntity } from '../../entities/account.entity';
import { AccountRepository } from './account.repo';

@Injectable()
export class AccountService {
  @InjectRepository(AccountEntity)
  private readonly accountRepository1: Repository<AccountEntity>;

  constructor(
    private readonly accountRepository: AccountRepository,
    private configService: ConfigService
  ) {}

  /**
   * 
   * @param data @InjectRepository(Mapping)
  private repo!: Repository<Mapping>;
   * @returns 
   */

  async createAccount(data: CreateAccountDto): Promise<any> {
    console.log(data, '接收到的数据');
    console.log(data, '');
    // const createdCat = new this.loginRepository(data);
    // return await createdCat.save();
    return;
  }

  async accountList(): Promise<AccountVo[]> {
    console.log(this.configService.get('database'), '数据库配置');
    // 方式一
    return await this.accountRepository1.find({ withDeleted: true });
    // 方式二
    // return await this.accountRepository1
    //   .createQueryBuilder('account')
    //   .select('account.id', 'id')
    //   .addSelect('account.username', 'username')
    //   .addSelect('account.createdAt', 'createdAt')
    //   .withDeleted()
    //   .getRawMany()
    //   .then((response) =>
    //     response.map((item) => {
    //       return { ...item, age: 20 };
    //     })
    //   );
  }
}
